import type { Local } from './types'
export const useLocal = defineStore({
  id: 'local',
  persist: true,
  state: () => <Local>({
    theme: 'light',
    lang: 'zh-CN',
    token: '',
    menu: [],
    usermsg: {},
    lock: false,
    isLogin: false,
    keepLogin: true,
    permission: [],
    droneOPeratorList: [],
    systemInfo: {},
    droneModelList: {},
    noticeCreateTime: 0,
    reserveType: 0,
    // 接收类型
    showSetting: {
      exploration: [],
      plane: true,
      boat: true,
      spect: true,
      fiveGA: true,
      operator: true,
      device: true,
      track: true,
      range: true,
      scan: true,
      logo: true,
      controlArea: true,
      correlation: true
    },
    mapKey: {
      // aMap: 'f6e6a050f46df0798a05b7ceed50a817',
      aMap: '77cc78c37d8b5425cd4d0f2fa76ded69',
      // aMap: 'bd7d25df22d89905e5257e575709c2cc'
    }
  }),
  actions: {
    async getUserMsg() {
      const { code, data } = await apiMyInfo()
      if (code != 200) return;
      this.usermsg = data
      this.usermsg.id == 3 ? 0 : this.usermsg.id,
      this.permission = useTreeToList(data.permission)?.map((item: any) => item.key)
      this.menu = useListToTree(useTreeToList(data.permission)?.filter((item: any) => item.type == 0))
    },
    async getdroneOPeratorList() {
      const { code, data } = await apispectOperatorList({
        page: 1,
        pageSize: 9999999
      })
      if (code != 200) return
      this.droneOPeratorList = data.list
      this.droneModelList = data.list.reduce((acc: any, item: any) => {
        const key = `${item.factoryIndex}${item.modelIndex}`;
        acc[key] = {
          name: item.model,
          factory: item.factory
        };
        return acc;
      }, {});
    },
    async getSystem() {
      const { code, data } = await apiSystem({ id: 1 })
      if (code != 200) return;
      this.systemInfo = data
    }
  }
})